package com.rika.controller;

import com.rika.pojo.Customer;
import com.rika.pojo.Vender;
import com.rika.response.QueryResult;
import com.rika.response.Result;
import com.rika.service.CustomerService;
import com.rika.util.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class CustomerController {
    @Resource
    private CustomerService customerService;
    @RequestMapping("getAllCustomer")
    public QueryResult selectAllCustomer(Integer currentPage, Integer pageSize){
        Page page=new Page(currentPage,pageSize);
        Map<String,Object> params=new HashMap<>();
        params.put("first",page.getFirst());
        params.put("max",page.getMax());
        List<Customer> list=customerService.selectCustomer(params);
        int total=customerService.countAll();
        return QueryResult.ok(total,list);
    }
    @RequestMapping("addCustomer")
    public Result insertVender(Customer customer){
        Result result=new Result();
        customerService.addCustomer(customer);
        result.setMsg("新增成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("deleteCustomer")
    public Result deleteVender(String customerCode){
        Result result=new Result();
        customerService.deleteCustomer(customerCode);
        result.setMsg("删除成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("selectByCustomerCode")
    public Result selectByCustomerCode(String customerCode){
        Result result=new Result();
        Customer list=customerService.selectByCustomerCode(customerCode);
        result.setCode(200);
        result.setData(list);
        return result;
    }
    @RequestMapping("updateCustomer")
    public Result updateVender(Customer customer){
        Result result=new Result();
        customerService.updateCustomer(customer);
        result.setMsg("修改成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("selectAllCustomerForPo")
    public Result selectAllCustomerForPo(){
        Result result=new Result();
        List<Customer> list=customerService.selectAllCustomerForPo();
        result.setCode(200);
        result.setData(list);
        return result;
    }
}
